import Koa from 'koa';
import router from 'koa-simple-router';
import co from 'co';
import serve from 'koa-static';
import render from 'koa-swig';
import babel_co from 'babel-core/register';
import babel_po from 'babel-polyfill';
import convert from 'koa-convert';

import initController from './controller/initController';
import Config from './config/config';

const app = new Koa();
initController.init(app, router);


app.context.render = co.wrap(render({
  root: Config.viewDir,
  autoescape: true,
  cache: 'memory', // disable, set to false 
  ext: 'html',
  writeBody: true
}));

app.use(serve(Config.staticDir));

export default function start() {
	app.listen(Config.port, () => {
		console.log('Sever has been started.');
	});
};
